package com.yanfan.maintain.controller;

import com.yanfan.maintain.domain.BaseDictEntity;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.maintain.domain.EquipmentRepair;
import com.yanfan.maintain.service.EquipmentRepairService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yanfan.maintain.domain.ImageUrl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 * 设备维修表(EquipmentRepair)表控制层
 *
 * @author makejava
 * @since 2023-03-13 17:54:59
 */
@RestController
@RequestMapping("/equipmentRepair")
@Api(tags = "设备维修管理")
public class EquipmentRepairController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private EquipmentRepairService equipmentRepairService;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 分页查询
     *
     * @param equipmentRepair 筛选条件
     * @return 查询结果
     */
    @PostMapping("/queryByPage")
    @ApiOperation("分页查询")
    public AjaxResult queryByPage(@RequestBody EquipmentRepair equipmentRepair) {
        PageHelper.startPage(equipmentRepair.getPageNum(), equipmentRepair.getPageSize());
        PageInfo<EquipmentRepair> pageInfo = new PageInfo<>(this.equipmentRepairService.queryByPage(equipmentRepair));
        return AjaxResult.success(pageInfo);
    }

    /**
     * @param equipmentRepair
     * @return
     */
    @ApiOperation("查询维修记录列表")
    //@PreAuthorize("@ss.hasPermi('maintain:alert:listByztGuid')")
    @GetMapping("/listByztGuid")
    public AjaxResult listByztGuid(EquipmentRepair equipmentRepair) {
        PageHelper.startPage(equipmentRepair.getPageNum(), equipmentRepair.getPageSize());
        PageInfo<EquipmentRepair> pageInfo = new PageInfo<>(this.equipmentRepairService.queryByPage(equipmentRepair));
        return AjaxResult.success(pageInfo);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/queryById/{id}")
    @ApiOperation("通过主键查询单条数据")
    public AjaxResult queryById(@PathVariable("id") Long id) {
        return AjaxResult.success(this.equipmentRepairService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param equipmentRepair 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation("新增数据")
    public AjaxResult add(@RequestBody EquipmentRepair equipmentRepair) {
        return AjaxResult.success(this.equipmentRepairService.insert(equipmentRepair));
    }

    /**
     * 编辑数据
     *
     * @param equipmentRepair 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    @ApiOperation("编辑数据")
    public AjaxResult edit(@RequestBody EquipmentRepair equipmentRepair) {
        return AjaxResult.success(this.equipmentRepairService.update(equipmentRepair));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/deleteById/{id}")
    @ApiOperation("删除数据")
    public AjaxResult deleteById(@PathVariable("id") Long id) {
        return AjaxResult.success(this.equipmentRepairService.deleteById(id));
    }


    /***
     *  根据设备Id查询设备详情信息
     * @param id
     * @return
     */
    @PostMapping("/deviceDetailById/{id}")
    @ApiOperation("根据设备Id查询设备详情信息")
    public AjaxResult deviceDetailById(@PathVariable("id") Long id) {
        return AjaxResult.success(this.equipmentRepairService.deviceDetailById(id));
    }


    @PostMapping("/orderList")
    @ApiOperation("查询订单信息")
    public AjaxResult orderList(@RequestBody BaseDictEntity baseDictEntity) {
        return AjaxResult.success(this.equipmentRepairService.orderList(baseDictEntity));
    }

    @PostMapping("/brandList")
    @ApiOperation("品牌列表")
    public AjaxResult brandList(@RequestBody BaseDictEntity baseDictEntity) {
        return AjaxResult.success(this.equipmentRepairService.brandList(baseDictEntity));
    }

    @PostMapping("/deviceTypeList")
    @ApiOperation("设备类型列表")
    public AjaxResult deviceTypeList(@RequestBody BaseDictEntity baseDictEntity) {
        return AjaxResult.success(this.equipmentRepairService.deviceTypeList(baseDictEntity));
    }

    /**
     * 关联备件图片信息查询
     *
     * @return
     */
    @GetMapping("/imgs")
    public TableDataInfo imgs(EquipmentRepair repair) {
        List<ImageUrl> list = this.equipmentRepairService.selectRepairImgs(repair);
        return getDataTable(list);
    }

    /**
     * 关联设备信息查询
     *
     * @return
     */
    @PostMapping("/imgs")
    public AjaxResult saveImgs(@RequestBody EquipmentRepair repair) {
        int i = this.equipmentRepairService.updateRepairImgs(repair);
        return toAjax(i);
    }

    /**
     * 关联备件图片信息查询
     *
     * @return
     */
    @GetMapping("/confirm-imgs")
    public TableDataInfo confirmImgs(EquipmentRepair repair) {
        List<ImageUrl> list = this.equipmentRepairService.selectConfirmRepairImgs(repair);
        return getDataTable(list);
    }

    /**
     * 关联设备信息查询
     *
     * @return
     */
    @PostMapping("/confirm-imgs")
    public AjaxResult saveConfirmImgs(@RequestBody EquipmentRepair repair) {
        int i = this.equipmentRepairService.updateConfirmRepairImgs(repair);
        return toAjax(i);
    }


}

